package logic.strategy;

import java.util.HashMap;
import java.util.Stack;

import logic.Continent;
import logic.Country;
import logic.moves.AddSoldierMove;
import logic.moves.GameMove;

public class ConquerStrategy extends Strategy {

	public ConquerStrategy(Continent continentToConquer) {
		addSoldiers = new Stack<AddSoldierMove>();
		cont = continentToConquer;
	}
	
	@Override
	public GameMove getNextMove() {
		if(player.getSoldiers() > 0 && addSoldiers.isEmpty())
		{
			fillAddSoldiersStack();
		}
		if(player.getSoldiers() > 0 && !addSoldiers.isEmpty())
		{
			return addSoldiers.pop();
		}
		return getAttackMove();
	}
	@Override 
	public boolean hasNextMove()
	{
		return(!player.isDefeated() && (!addSoldiers.isEmpty() || player.getSoldiers() > 0 || getAttackMove() != null));
	}
	
	/**
	 * Return all the countries in the target continent which are
	 * not owned by player
	 */
	public HashMap<String, Country> getTargetCountries() {
		HashMap<String, Country> rs = new HashMap<String,Country>();
		for (Country country : cont.getTerritoriesContained())
			if (!country.getOwner().equals(player))
				rs.put(country.getName(), country);
		return rs;
	}

}
